<template>
  <div class="container">
    <div class="app-container">
      <el-button type="primary" size="mini" class="per-btn" @click="showDialog = true">添加权限</el-button>
      <el-table :data="list" default-expand-all row-key="id">
        <el-table-column label="名称" prop="name" />
        <el-table-column label="标识" prop="code" />
        <el-table-column label="描述" prop="description" />
        <el-table-column label="操作">
          <template v-slot="{row}">
            <el-button v-if="row.type===1" size="mini" type="text" @click="showDialog=true">添加</el-button>
            <el-button size="mini" type="text">编辑</el-button>
            <el-button size="mini" type="text">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 放置添加弹层 -->
    <add-permission
      :show-dialog.sync="showDialog"
    />
  </div>
</template>
<script>
import AddPermission from './components/add-permission.vue'
import { getPermission } from '@/api/permission'
import { transListToTreeData } from '@/utils/index'
export default {
  name: 'Permission',
  components: {
    AddPermission
  },
  data() {
    return {
      list: [], // 存储权限列表
      showDialog: false
    }
  },
  created() {
    this.getPermission()
  },
  methods: {
    async getPermission() {
      this.list = transListToTreeData(await getPermission(), 0)
      // console.log(this.list)
    }
  }
}
</script>
<style>
.per-btn{
  margin: 10px;
}
</style>
